# Function for Double clustered standard errors
double_clustered_se <- function(m, get="Std. Error"){
  
  require(lmtest, quietly = TRUE)
  require(plm, quietly = TRUE)
  
  # Double-clustering formula (Thompson, 2011) for two-sided standard errors
  vcovDC <- function(x, ...){
    vcovHC(x, cluster="group", ...) + vcovHC(x, cluster="time", ...) - 
      vcovHC(x, method="white1", ...)
  }
  
  # Run Test
  res <- coeftest(m,vcov=function(x) vcovDC(x, type="HC1"))
  
  # Return
  return(res[,get])
}
